// import { IBaseTable } from '@feidao/web/atom/nodejs/db/interfaces';
import count from '@dfeidao/atom-nodejs/db/count';
import operate from '@dfeidao/atom-nodejs/db/operate';
import doc_code from '@dfeidao/atom-nodejs/msg/doc-code';


interface Message {
	menu_name: string;
	client_type: string;
	icon: string;
	description: string;
	priority: string;
	productid: string;
	systemid: string;
	formid: string;
	refsystemid: string;
	parent_no: string;
	background: string;
	is_show: boolean;
}

export default async function atom(msg: Message, action_id: string, session_id: string, spaceid: string) {

	const systemid = '12';
	const menu_no = await doc_code(action_id, session_id, systemid, 'BM0011278', 'P07', 1);
	const c = count(action_id, session_id, systemid);
	c.prepare('pub_menu', { productid: msg.productid, menu_name: msg.menu_name, client_type: msg.client_type });
	const [t] = await c.exec();
	// return t;
	if (t > 0) {
		return 'other';
	}
	const { exec, insert } = operate(action_id, session_id, systemid);

	insert('pub_menu', { menu_name: msg.menu_name, client_type: msg.client_type, icon: msg.icon, menu_no: menu_no.results[0], description: msg.description, priority: msg.priority, productid: msg.productid, systemid: msg.systemid, formid: msg.formid, background: msg.background, refsystemid: msg.refsystemid, parent_no: msg.parent_no, is_show: msg.is_show, is_single: false, is_offline: false, is_guest: false, show_type: '' });
	const res = await exec();

	if (res.code === 1) {
		return 'success';
	} else {
		return 'fail';
	}
}
